#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;

class Point{
public:
    Point(int x, int y)
    :_x(x)
    ,_y(y)
    {
        cout << "Point(int,int)" << endl;
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

    Point(const Point & rhs)
    :_x(rhs._x)
    ,_y(rhs._y)
    {
        cout << "Point(const Point &)" << endl;
    }

private:
    int _x;
    int _y;
};


void test(){
    //将要在vector中存储point对象
    vector<Point> vec;
    //先不使用reserve
    vec.reserve(10);
    vec.push_back(Point(1, 2));
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.push_back(Point(1, 2));
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.push_back(Point(1, 2));
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.push_back(Point(1, 2));
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.push_back(Point(1, 2));
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
}


void test2(){
    //此时是直接在vector所属的空间中直接创建出该point对象
    //并不会出现复制的情况
    //将要在vector中存储point对象
    vector<Point> vec;
    //先不使用reserve
    vec.reserve(10);
    vec.emplace_back(1, 2);
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.emplace_back(1, 2);
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.emplace_back(1, 2);
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.emplace_back(1, 2);
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
    vec.emplace_back(1, 2);
    cout << vec.size() << endl;
    cout << vec.capacity() << endl;
}

int main()
{
    test();
    return 0;
}


